# 检查页相关事件绑定
import share
from util.ComboBoxUtil import ComboBoxUtil
from util.requestUtil import requestUtil

class event:
    def __init__(self):
        self.ui = share.SI.main.ui
        # 开始检查事件
        self.ui.start_check_button.clicked.connect(lambda: self.findOriginalById())
        self.ui.start_check_button.clicked.connect(lambda: self.findOriginalById())

    def findOriginalById(self):
        value = ComboBoxUtil(self.ui.source_list_comboBox).getValue()
        value1 = ComboBoxUtil(self.ui.organization_comboBox).getValue()
        dataMap = requestUtil("/original/findByOIdAndOId/" + str(value1) + "/" + str(value),"GET").dataMap

class bind:
    def __init__(self):
        self.ui = share.SI.main.ui

    # 更新下拉数据
    def dataUpdate(self):
        try:
            # 解绑分组切换事件
            self.ui.group_comboBox.currentTextChanged.disconnect()
            delattr(self.ui.group_comboBox, "data_list")
        except:
            pass
        # 清空公司，版本，原表下拉列表
        self.ui.organization_comboBox.clear()
        self.ui.source_list_comboBox.clear()
        # 查询公司下拉列表
        dataMap = requestUtil("/organization","GET").dataMap
        ComboBoxUtil(self.ui.organization_comboBox).addItems(dataMap["data"],"name","id")
        # 绑定下拉框选值变化事件
        self.ui.organization_comboBox.currentTextChanged.connect(lambda: self.change_selected(self.ui.organization_comboBox))

    # 下拉框变化触发事件
    def change_selected(self,comboBox):
        value = ComboBoxUtil(comboBox).getValue()
        try:
            delattr(self.ui.source_list_comboBox, "data_list")
        except:
            pass
        self.ui.source_list_comboBox.clear()
        if value != "请选择":
            dataMap = requestUtil("/original/findByOId/" + str(value),"GET").dataMap
            ComboBoxUtil(self.ui.source_list_comboBox).addItems(dataMap["data"],"name","id")
